home *** CD-ROM | disk | FTP | other *** search
- unit Demounit;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, Menus, Htmlview, StdCtrls, HtmlSubs, FontDlg,
- htmlabt, Submit;
-
- const
- MaxHistories = 6; {size of History list}
- type
- TForm1 = class(TForm)
- OpenDialog: TOpenDialog;
- MainMenu: TMainMenu;
- Panel1: TPanel;
- Panel2: TPanel;
- Panel3: TPanel;
- Viewer: THTMLViewer;
- File1: TMenuItem;
- Open: TMenuItem;
- options1: TMenuItem;
- ShowImages: TMenuItem;
- Fonts: TMenuItem;
- Edit1: TEdit;
- Reload: TButton;
- BackButton: TButton;
- FwdButton: TButton;
- HistoryMenuItem: TMenuItem;
- Exit: TMenuItem;
- N1: TMenuItem;
- Print1: TMenuItem;
- PrintDialog: TPrintDialog;
- About1: TMenuItem;
- Edit2: TMenuItem;
- Find1: TMenuItem;
- FindDialog: TFindDialog;
- procedure OpenFileClick(Sender: TObject);
- procedure HotSpotChange(Sender: TObject; const URL: string);
- procedure HotSpotClick(Sender: TObject; const URL: string;
- var Handled: boolean);
- procedure ShowImagesClick(Sender: TObject);
- procedure ReloadClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FwdBackClick(Sender: TObject);
- procedure HistoryClick(Sender: TObject);
- procedure HistoryChange(Sender: TObject);
- procedure ExitClick(Sender: TObject);
- procedure FontColorsClick(Sender: TObject);
- procedure Print1Click(Sender: TObject);
- procedure About1Click(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure SubmitEvent(Sender: TObject; Action, Method: String;
- Results: TStringList);
- procedure Find1Click(Sender: TObject);
- procedure FindDialogFind(Sender: TObject);
- procedure ProcessingHandler(Sender: TObject; ProcessingOn: Boolean);
- private
- { Private declarations }
- SndHandle : THandle;
- PlaySound : function (lpszSoundName: PChar; uFlags: Word): Bool;
- Histories: array[0..MaxHistories-1] of TMenuItem;
- procedure FontChange(Sender: TObject);
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- I: integer;
- begin
- OpenDialog.InitialDir := ExtractFilePath(ParamStr(0));
-
- {make sure mmsystem.dll exists before calling sndPlaySound}
- SndHandle := LoadLibrary('mmsystem.dll');
- if SndHandle >= 32 then
- @PlaySound := GetProcAddress(SndHandle, 'sndPlaySound');
-
- Viewer.HistoryMaxCount := MaxHistories; {defines size of history list}
-
- for I := 0 to MaxHistories-1 do
- begin {create the MenuItems for the history list}
- Histories[I] := TMenuItem.Create(HistoryMenuItem);
- HistoryMenuItem.Insert(I, Histories[I]);
- with Histories[I] do
- begin
- Visible := False;
- OnClick := HistoryClick;
- Tag := I;
- end;
- end;
- end;
-
- procedure TForm1.FormShow(Sender: TObject);
- begin
- if (ParamCount >= 1) then
- Viewer.LoadFromFile(ParamStr(1)); {Parameter is file to load}
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- if SndHandle >= 32 then FreeLibrary(SndHandle);
- end;
-
- procedure TForm1.OpenFileClick(Sender: TObject);
- begin
- if Viewer.CurrentFile <> '' then
- OpenDialog.InitialDir := ExtractFilePath(Viewer.CurrentFile);
- if OpenDialog.Execute then
- begin
- Viewer.LoadFromFile(OpenDialog.Filename);
- Caption := Viewer.DocumentTitle;
- end;
- end;
-
- procedure TForm1.HotSpotChange(Sender: TObject; const URL: string);
- {mouse moved over or away from a hot spot. Change the status line}
- begin
- Panel1.Caption := URL;
- end;
-
- procedure TForm1.HotSpotClick(Sender: TObject; const URL: string;
- var Handled: boolean);
- {This routine handles what happens when a hot spot is clicked. The assumption
- is made that DOS filenames are being used. .EXE and .WAV files are handled
- here, but other file types could be easily added.
-
- If the URL is handled here, set Handled to True. If not handled here, set it
- to False and ThtmlViewer will handle it.}
- const
- snd_Async = $0001; { play asynchronously }
- var
- PC: array[0..255] of char;
- S, Params: string[80];
- Ext: string[5];
- I, J, K: integer;
-
- begin
- Handled := False;
- I := Pos(':', URL);
- J := Pos('FILE:', UpperCase(URL));
- if (I <= 2) or (J > 0) then
- begin {apparently the URL is a filename}
- S := URL;
- K := Pos(' ', S);
- if K > 0 then
- begin
- Params := Copy(S, K, 255); {save any parameters}
- S[0] := chr(K-1); {truncate S}
- end
- else Params := '';
- S := Viewer.HTMLExpandFileName(S);
- Ext := Uppercase(ExtractFileExt(S));
- if Ext = '.WAV' then
- begin
- Handled := True;
- if Assigned(PlaySound) then
- PlaySound(StrPCopy(PC, S), snd_ASync);
- end
- else if Ext = '.EXE' then
- begin
- Handled := True;
- WinExec(StrPCopy(PC, S+Params), sw_Show);
- end;
- {else ignore other extensions}
- Edit1.Text := URL;
- end
- else Edit1.Text := URL; {other protocall, mailto:, ftp:, etc.}
- end;
-
- procedure TForm1.ShowImagesClick(Sender: TObject);
- {The Show Images menu item was clicked}
- begin
- With Viewer do
- begin
- ViewImages := not ViewImages;
- (Sender as TMenuItem).Checked := ViewImages;
- end;
- end;
-
- procedure TForm1.ReloadClick(Sender: TObject);
- {the Reload button was clicked}
- var
- Pos: LongInt;
- begin
- with Viewer do
- begin
- ReLoad.Enabled := False;
- Pos := Position; {save the postion}
- LoadFromFile(CurrentFile); {load again}
- Position := Pos; {restore position}
- Reload.Enabled := CurrentFile <> '';
- end;
- end;
-
- procedure TForm1.FwdBackClick(Sender: TObject);
- {Either the Forward or Back button was clicked}
- begin
- with Viewer do
- begin
- if Sender = BackButton then
- HistoryIndex := HistoryIndex +1
- else
- HistoryIndex := HistoryIndex -1;
- end;
- end;
-
- procedure TForm1.HistoryChange(Sender: TObject);
- {This event occurs when something changes history list}
- var
- I: integer;
- begin
- with Sender as ThtmlViewer do
- begin
- {check to see which buttons are to be enabled}
- FwdButton.Enabled := HistoryIndex > 0;
- BackButton.Enabled := HistoryIndex < History.Count-1;
-
- {Enable and caption the appropriate history menuitems}
- HistoryMenuItem.Visible := History.Count > 0;
- for I := 0 to MaxHistories-1 do
- with Histories[I] do
- if I < History.Count then
- Begin
- Caption := History.Strings[I];
- Visible := True;
- Checked := I = HistoryIndex;
- end
- else Histories[I].Visible := False;
- Caption := DocumentTitle; {keep the caption updated}
- end;
- end;
-
- procedure TForm1.HistoryClick(Sender: TObject);
- {A history list menuitem got clicked on}
- begin
- {Changing the HistoryIndex loads and positions the appropriate document}
- Viewer.HistoryIndex := (Sender as TMenuItem).Tag;
- end;
-
- procedure TForm1.ExitClick(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TForm1.FontChange(Sender: TObject);
- begin
- with FontForm do
- begin
- Viewer.DefFontName := FontName;
- Viewer.DefFontColor := FontColor;
- Viewer.DefHotSpotColor := HotSpotColor;
- Viewer.DefBackground := Background;
- end;
- end;
-
- procedure TForm1.FontColorsClick(Sender: TObject);
- var
- I: Integer;
- FontForm: TFontForm;
- begin
- try
- FontForm := TFontForm.Create(Self);
- with FontForm do
- begin
- FontName := Viewer.DefFontName;
- FontColor := Viewer.DefFontColor;
- FontSize := Viewer.DefFontSize;
- HotSpotColor := Viewer.DefHotSpotColor;
- Background := Viewer.DefBackground;
- if ShowModal = mrOK then
- begin
- Viewer.DefFontName := FontName;
- Viewer.DefFontColor := FontColor;
- Viewer.DefFontSize := FontSize;
- Viewer.DefHotSpotColor := HotSpotColor;
- Viewer.DefBackground := Background;
- ReloadClick(Self); {reload to see how it looks}
- end;
- end;
- finally
- FontForm.Free;
- end;
- end;
-
- procedure TForm1.Print1Click(Sender: TObject);
- begin
- with PrintDialog do
- if Execute then
- if PrintRange = prAllPages then
- viewer.Print(1, 9999)
- else
- Viewer.Print(FromPage, ToPage);
- end;
-
- procedure TForm1.About1Click(Sender: TObject);
- begin
- try
- AboutBox := TAboutBox.Create(Self);
- AboutBox.ShowModal;
- finally
- AboutBox.Free;
- end;
- end;
-
-
- procedure TForm1.SubmitEvent(Sender: TObject; Action, Method: String;
- Results: TStringList);
- begin
- with SubmitForm do
- begin
- ActionText.Text := Action;
- MethodText.Text := Method;
- ResultBox.Items := Results;
- Results.Free;
- Show;
- end;
- end;
-
- procedure TForm1.Find1Click(Sender: TObject);
- begin
- FindDialog.Execute;
- end;
-
- procedure TForm1.FindDialogFind(Sender: TObject);
- begin
- with FindDialog do
- begin
- if not Viewer.Find(FindText, frMatchCase in Options) then
- MessageDlg('No further occurances of "'+FindText+'"', mtInformation, [mbOK], 0);
- end;
- end;
-
- procedure TForm1.ProcessingHandler(Sender: TObject; ProcessingOn: Boolean);
- begin
- if ProcessingOn then
- begin {disable various buttons and menuitems during processing}
- FwdButton.Enabled := False;
- BackButton.Enabled := False;
- Reload.Enabled := False;
- Print1.Enabled := False;
- Find1.Enabled := False;
- Open.Enabled := False;
- end
- else
- begin
- FwdButton.Enabled := Viewer.HistoryIndex > 0;
- BackButton.Enabled := Viewer.HistoryIndex < Viewer.History.Count-1;
- ReLoad.Enabled := Viewer.CurrentFile <> '';
- Print1.Enabled := Viewer.CurrentFile <> '';
- Find1.Enabled := Viewer.CurrentFile <> '';
- Open.Enabled := True;
- end;
- end;
-
- end.
-